
var orgId;
var userId;

$(function() {
	 // 通过window.screen.width获取设备的宽度
    // var offWidth = window.screen.width;
    // 通过document.body.clientWidth网页可见区域的宽度
    var offWidth = document.body.clientWidth
    // 设计稿1rem = 100px
    document.getElementsByTagName("html")[0].style.fontSize = offWidth*(100/1920) + 'px'; //把rem的值复制给顶级标签html的font-size
    console.log('offWidth:'+offWidth)

    window.onresize = function(){
        location.reload()
    }

	orgId = GetQueryString("orgId");
	userId = GetQueryString("userId");
	
    validateRule();
    
    $(".i-checks").iCheck({checkboxClass:"icheckbox_square-green-login"});
	$('.imgcode').click(function() {
		var url = ctx + "captcha/captchaImage?type=" + captchaType + "&s=" + Math.random();
		$(".imgcode").attr("src", url);
	});
    
});

// 模态框
let hideView = function () {
    document.querySelector('.bg-content').style.display = 'none'
    document.querySelector('.login-content').style.display = 'none'
}
let showView = function () {
    document.querySelector('.bg-content').style.display = 'block'
    document.querySelector('.login-content').style.display = 'block'
}

function GetQueryString(name)
{
	 //var urldecode = decodeURI(window.location.search);
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);//search,查询？后面的参数，并匹配正则
     
     if(r!=null)return  unescape(r[2]); return null;
}

$.validator.setDefaults({
    submitHandler: function() {
		login();
    }
});

function login() {
	//alert(123454);
	$.modal.loading($("#bindSubmit").data("loading"));
    var companyAccount = $.common.trim($("input[name='companyAccount']").val());
	var loginName = $.common.trim($("input[name='loginName']").val());
    var loginPwd = $.common.trim($("input[name='loginPwd']").val());
    $.ajax({
        type: "post",
        url: ctx + "oaPCBind",
        data: {
        	"oaOrgId": orgId,
        	"oaUserId": userId,
        	"companyAccount": companyAccount,
            "loginName": loginName,
            "loginPwd": loginPwd
        },
        success: function(r) {
            if (r.code == 0) {
            	location.href = r.data.bindURL;
            } else {
            	$.modal.closeLoading();
            	$('.imgcode').click();
            	$.modal.msg(r.msg);
            }
        }
    });
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#bindForm").validate({
        rules: {
        	companyAccount: {
                required: true
            },
        	loginName: {
                required: true
            },
            loginPwd: {
                required: true
            }
        },
        messages: {
        	companyAccount: {
                required: "",
            },
        	loginName: {
                required: "",
            },
            loginPwd: {
                required: "",
            }
        }
    })
}
